package chpt06;

import java.util.Objects;

public class StudentV2 {
	private String sName;
	private int sAge;
	// getter/setter代码
	public String getsName() {
		return sName;
	}

	public void setsName(String sName) {
		this.sName = sName;
	}

	public int getsAge() {
		return sAge;
	}

	public void setsAge(int sAge) {
		this.sAge = sAge;
	}
	// 无参数构造方法、带参数构造方法、重写toString()方法
	public StudentV2() {		
	}
	
	public StudentV2(String sName, int sAge) {
		this.sName = sName;
		this.sAge = sAge;
	}


	@Override
	public int hashCode() {
		return Objects.hash(sName,sAge);
	}
	
	@Override
	public String toString() {
		return "StudentV2 [sName=" + sName + ", sAge=" + sAge + "]";
	}

	@Override
	public boolean equals(Object obj) {
		if(this == obj) return true;
		if(obj == null || this.getClass() != obj.getClass()) 
			return false;
		StudentV2 other = (StudentV2)obj;
		// 学生的姓名和年龄相同，表示为相同的Student2对象
		return this.sAge==other.sAge 
				&& Objects.equals(this.sName,other.sName);
	}
}
